package com.example.hello_world.mianshi;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Display;
import android.view.View;

import com.example.hello_world.R;

public class activity02 extends AppCompatActivity {

    private SwitchCompat switchCompat;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity02);
        switchCompat=findViewById(R.id.switch01);

        SharedPreferences sp=getSharedPreferences("statement", MODE_PRIVATE);
        final SharedPreferences.Editor editor=sp.edit();
        String stament = sp.getString("save", "0");

        if(stament.equals("1")){
            switchCompat.setChecked(true);
        }else{
            switchCompat.setChecked(false);
        }

        switchCompat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(switchCompat.isChecked()){
                    editor.putString("save","1");
                }else{
                    editor.putString("save","0");
                }
                editor.commit();
            }
        });
    }
}